using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the InternetColor class.
	/// </summary>
	[Serializable]
	public partial class InternetColorCollection : ActiveList<InternetColor, InternetColorCollection> 
	{	   
		public InternetColorCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the InternetColor table.
	/// </summary>
	[Serializable]
	public partial class InternetColor : ActiveRecord<InternetColor>
	{
		#region .ctors and Default Settings
		
		public InternetColor()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public InternetColor(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public InternetColor(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public InternetColor(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("InternetColor", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarInternetColorID = new TableSchema.TableColumn(schema);
				colvarInternetColorID.ColumnName = "InternetColorID";
				colvarInternetColorID.DataType = DbType.Int32;
				colvarInternetColorID.MaxLength = 0;
				colvarInternetColorID.AutoIncrement = true;
				colvarInternetColorID.IsNullable = false;
				colvarInternetColorID.IsPrimaryKey = false;
				colvarInternetColorID.IsForeignKey = false;
				colvarInternetColorID.IsReadOnly = false;
				colvarInternetColorID.DefaultSetting = @"";
				colvarInternetColorID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInternetColorID);
				
				TableSchema.TableColumn colvarColorCode = new TableSchema.TableColumn(schema);
				colvarColorCode.ColumnName = "ColorCode";
				colvarColorCode.DataType = DbType.Int32;
				colvarColorCode.MaxLength = 0;
				colvarColorCode.AutoIncrement = false;
				colvarColorCode.IsNullable = false;
				colvarColorCode.IsPrimaryKey = true;
				colvarColorCode.IsForeignKey = false;
				colvarColorCode.IsReadOnly = false;
				colvarColorCode.DefaultSetting = @"";
				colvarColorCode.ForeignKeyTableName = "";
				schema.Columns.Add(colvarColorCode);
				
				TableSchema.TableColumn colvarColorName = new TableSchema.TableColumn(schema);
				colvarColorName.ColumnName = "ColorName";
				colvarColorName.DataType = DbType.String;
				colvarColorName.MaxLength = 50;
				colvarColorName.AutoIncrement = false;
				colvarColorName.IsNullable = true;
				colvarColorName.IsPrimaryKey = false;
				colvarColorName.IsForeignKey = false;
				colvarColorName.IsReadOnly = false;
				colvarColorName.DefaultSetting = @"";
				colvarColorName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarColorName);
				
				TableSchema.TableColumn colvarDateAdded = new TableSchema.TableColumn(schema);
				colvarDateAdded.ColumnName = "DateAdded";
				colvarDateAdded.DataType = DbType.DateTime;
				colvarDateAdded.MaxLength = 0;
				colvarDateAdded.AutoIncrement = false;
				colvarDateAdded.IsNullable = false;
				colvarDateAdded.IsPrimaryKey = false;
				colvarDateAdded.IsForeignKey = false;
				colvarDateAdded.IsReadOnly = false;
				colvarDateAdded.DefaultSetting = @"";
				colvarDateAdded.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateAdded);
				
				TableSchema.TableColumn colvarDateModified = new TableSchema.TableColumn(schema);
				colvarDateModified.ColumnName = "DateModified";
				colvarDateModified.DataType = DbType.DateTime;
				colvarDateModified.MaxLength = 0;
				colvarDateModified.AutoIncrement = false;
				colvarDateModified.IsNullable = false;
				colvarDateModified.IsPrimaryKey = false;
				colvarDateModified.IsForeignKey = false;
				colvarDateModified.IsReadOnly = false;
				colvarDateModified.DefaultSetting = @"";
				colvarDateModified.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateModified);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("InternetColor",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("InternetColorID")]
		public int InternetColorID 
		{
			get { return GetColumnValue<int>("InternetColorID"); }

			set { SetColumnValue("InternetColorID", value); }

		}

		  
		[XmlAttribute("ColorCode")]
		public int ColorCode 
		{
			get { return GetColumnValue<int>("ColorCode"); }

			set { SetColumnValue("ColorCode", value); }

		}

		  
		[XmlAttribute("ColorName")]
		public string ColorName 
		{
			get { return GetColumnValue<string>("ColorName"); }

			set { SetColumnValue("ColorName", value); }

		}

		  
		[XmlAttribute("DateAdded")]
		public DateTime DateAdded 
		{
			get { return GetColumnValue<DateTime>("DateAdded"); }

			set { SetColumnValue("DateAdded", value); }

		}

		  
		[XmlAttribute("DateModified")]
		public DateTime DateModified 
		{
			get { return GetColumnValue<DateTime>("DateModified"); }

			set { SetColumnValue("DateModified", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public Adex.InternetLogCollection InternetLogRecords()
		{
			return new Adex.InternetLogCollection().Where(InternetLog.Columns.ColorCode, ColorCode).Load();
		}

		#endregion
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varColorCode,string varColorName,DateTime varDateAdded,DateTime varDateModified)
		{
			InternetColor item = new InternetColor();
			
			item.ColorCode = varColorCode;
			
			item.ColorName = varColorName;
			
			item.DateAdded = varDateAdded;
			
			item.DateModified = varDateModified;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varInternetColorID,int varColorCode,string varColorName,DateTime varDateAdded,DateTime varDateModified)
		{
			InternetColor item = new InternetColor();
			
				item.InternetColorID = varInternetColorID;
				
				item.ColorCode = varColorCode;
				
				item.ColorName = varColorName;
				
				item.DateAdded = varDateAdded;
				
				item.DateModified = varDateModified;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string InternetColorID = @"InternetColorID";
			 public static string ColorCode = @"ColorCode";
			 public static string ColorName = @"ColorName";
			 public static string DateAdded = @"DateAdded";
			 public static string DateModified = @"DateModified";
						
		}

		#endregion
	}

}

